using StackCalc.Instructions;

namespace StackCalc.Parsing
{
	/// <summary>
	/// Parsing unit for instructions.
	/// </summary>
	public interface IParsingUnit<out TInstruction> where TInstruction : IInstruction
	{
		/// <summary>
		/// Determines whether this instance can parse the specified input.
		/// </summary>
		/// <param name="input">The input.</param>
		/// <returns>
		/// "true" if this instance can parse the specified input; otherwise, "false".
		/// </returns>
		bool CanParse(string input);

		/// <summary>
		/// Determines whether the syntax of the specified input is correct.
		/// </summary>
		/// <param name="input">The input.</param>
		/// <returns>
		/// True if a syntax error is present.
		/// </returns>
		bool HasSyntaxError(string input);

		/// <summary>
		/// Gets the error description if a syntax error happens.
		/// </summary>
		/// <returns>Error description.</returns>
		string GetErrorDescription();

		/// <summary>
		/// Parses the specified input into an instruction.
		/// </summary>
		/// <param name="input">The input.</param>
		/// <returns>Parsed instruction.</returns>
		TInstruction Parse(string input);

		/// <summary>
		/// Trunkates the specified input.
		/// </summary>
		/// <param name="input">The input.</param>
		/// <returns>Trunkated input.</returns>
		string Trunkate(string input);
	}
}